// Created by Xslt generator for Eclipse.
// XSL :  not found (java.io.FileNotFoundException:  (Bad file descriptor))
// Default XSL used : easystruts.jar$org.easystruts.xslgen.JavaClass.xsl

package com.ba360.struts.form;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.ba360.portal.common.PortalConstants;
import com.ba360.portal.database.dbo.User;
import com.ba360.portal.util.Formatter;

/**
 * RegistrationForm.java created by EasyStruts - XsltGen.
 * http://easystruts.sf.net created on 04-01-2004
 * 
 * XDoclet definition:
 * 
 * @struts:form name="RegistrationForm"
 */
public class RegistrationForm extends ActionForm {

	// --------------------------------------------------------- Instance
	// Variables

	
	/*New variable declared by mani on 09 Feb 09*/
	private String email;	
	private String city;
	private String password;	
	private String email_confirm;
	private String password_confirm;
	
	// --------------------------------------------------------- Methods

	/**
	 * Method validate
	 * 
	 * @param ActionMapping
	 *            mapping
	 * @param HttpServletRequest
	 *            request
	 * @return ActionErrors
	 */
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {

		ActionErrors errors = null;
		String action = request.getParameter(PortalConstants.ACTION);

		errors = new ActionErrors();
		HttpSession session = request.getSession();
		if (action.equals("Save")) 
		{		
			/*
			 * Check the email field if it is empty then error will be shown to the user
			 */
				System.out.println("The bean-email is:"+email);
				System.out.println("The bean-confirmemail is:"+email_confirm);
				System.out.println("The bean-city is:"+city);
				System.out.println("The bean-password is:"+password);
				System.out.println("The bean-confirm password is:"+password_confirm);
					if (email == null || email.trim().length() == 0)
					{
						errors.add("Email", new ActionError("error.email.value"));
					}
			/*
			 * If email is not empty then we will validate the email format
			 */
					if (email!=null)
					{
						if (email.indexOf("@") == -1 || email.indexOf(".") == -1 || email.length() < 8)
						{
							errors.add("Email", new ActionError("error.invalidemail.value"));
						}	
					}
			/*
			 * Check the confirm field if it is empty then error will be shown to the user
			 */
					if(email_confirm == null || email_confirm.trim().length() == 0)
					{
						errors.add("Confirm Email",new ActionError("error.email.value"));
					}
			/*
			 * If confirm is not empty then we will validate the confirm email with email
			 */
					if(email_confirm !=null)
					{
						if(!email_confirm.equals(email))
						{
							errors.add("Confirm Email",new ActionError("error.email.value"));
						}
					}
			/*
			 * Check the city field if it is empty then error will be shown to the user
			 */
					if (city==null || city.trim().length()==0) 
					{
						errors.add("City",new ActionError("error.city.value"));
					}
			/*
			 * Check the password field if it is empty then error will be shown to the user
			 */
			if(password == null || password.trim().length() == 0)
			{
				errors.add("Password", new ActionError("error.password.value"));
			}			
			if(password !=null)
			{
				if(password.trim().length()<6)
				{
					errors.add("Password", new ActionError("error.password.value"));
				}
			}
			
			if(password_confirm !=null)
			{
				if(!password_confirm.equals(password))
				{
					errors.add("Confirm Password",new ActionError("error.password.value"));
				}
			}
		} 
		
		else if (action.equals("UpdateInfo")) 
		{
			/*
			 * Check the email field if it is empty then error will be shown to the user
			 */
					if (email == null || email.trim().length() == 0)
					{
						errors.add("Email", new ActionError("error.email.value"));
					}
			/*
			 * If email is not empty then we will validate the email format
			 */
					if (email!=null)
					{
						if (email.indexOf("@") == -1 || email.indexOf(".") == -1 || email.length() < 8)
						{
							errors.add("Email", new ActionError("error.invalidemail.value"));
						}	
					}
			/*
			 * Check the city field if it is empty then error will be shown to the user
			 */
					if (city==null || city.trim().length()==0) 
					{
						errors.add("City",new ActionError("error.city.value"));
					}
			/*
			 * Check the password field if it is empty then error will be shown to the user
			 */
			if(password == null || password.trim().length() == 0)
			{
				errors.add("Password", new ActionError("error.password.value"));
			}			
			if(password !=null)
			{
				if(password.trim().length()<6)
				{
					errors.add("Password", new ActionError("error.password.size"));
				}
			}			
		}
		else if (action.equals("ViewInfo")) {
			User user = (User) session.getAttribute(PortalConstants.USER);
			if (user == null) {
				errors.add("NOT_LOGGED", new ActionError("error.user.nologin"));
				return errors;
			}	
			
			this.email = user.getEmail();				
			this.password = user.getPwd();
			this.city = user.getCity();
		}

		return errors;
	}

	/**
	 * Method reset
	 * 
	 * @param ActionMapping
	 *            mapping
	 * @param HttpServletRequest
	 *            request
	 */
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		email = null;
		email_confirm =null;
		city = null;
		password = null;
		password_confirm=null;
	
	}

	
	public String getPassword() {
		return password;
	}

	/**
	 * Set the gender.
	 * 
	 * @param gender
	 *            The gender to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/* Returns the email.
	 * 
	 * @return String
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * Set the email.
	 * 
	 * @param email
	 *            The email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * Returns the city.
	 * 
	 * @return String
	 */
	public String getCity() {
		return city;
	}

	/**
	 * Set the city.
	 * 
	 * @param city
	 *            The city to set
	 */
	public void setCity(String city) {
		this.city = city;
	}
	public String getPassword_confirm() {
		return password_confirm;
	}

	public void setPassword_confirm(String password_confirm) {
		this.password_confirm = password_confirm;
	}

	public String getEmail_confirm() {
		return email_confirm;
	}

	public void setEmail_confirm(String email_confirm) {
		this.email_confirm = email_confirm;
	}

	

}